package com.example.neusoft215gdh.androidpro_21.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.neusoft215gdh.androidpro_21.JavaBean.Order;
import com.example.neusoft215gdh.androidpro_21.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Rainbow on 2017/11/1.
 */

public class OrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Order> orderList = new ArrayList<>();
    private Context context;//上下文对象
    private LayoutInflater layoutInflater;
    //构造函数
    public OrderAdapter(Context context, List<Order> orderList ){
        this.context=context;//保存上下文
        layoutInflater=LayoutInflater.from(context);
        this.orderList.addAll(orderList);//显示数据

    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View itemView = layoutInflater.inflate(R.layout.item_order,parent,false);

        OrderViewHolder holder=new OrderViewHolder(itemView);

        return holder;
    }
    //绑定数据
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        OrderViewHolder orderViewHolder = (OrderViewHolder) holder;
        Order order  = orderList.get(position);


        //获取具体的数据值


        String name = order.getName();
        String pic = order.getThumb();
        String price = order.getPrice();
        String sumprice = order.getPay();
        String time = order.getUpdate_time();
        String number = order.getId();

        orderViewHolder.order_name.setText(name);
        orderViewHolder.order_sumprice.setText(sumprice+"元");
        orderViewHolder.order_price.setText("￥"+price);
        orderViewHolder.order_time.setText(time);
        orderViewHolder.order_number.setText(number);

        if (pic != "") {
            Picasso.with(context).load("http://172.24.10.175/workout/Uploads/"+pic).
                    into(orderViewHolder.order_pic);
        }


        //页面跳转
        orderViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //启动新的Activity—店铺详情（菜谱列表）。

              /*  Intent intent = new Intent(context, PeixunDetialActivity.class);
                //传值
                intent.putExtra("peixunID", id);
                //在适配器里调用StarActivity方法
                context.startActivity(intent);*/
            }
        });

    }

    //显示条目的数量
    @Override
    public int getItemCount() {
        return orderList.size();
    }

}
